// src/api/order.ts
import request from '@/utils/request';
import type { IOrder, IOrderPageResult, IOrderPageQuery, IOrderStatistics, IOrderDetail } from '@/types/order';

/**
 * 订单搜索 (分页查询)
 * @param params - 查询参数
 */
export const getOrderPage = (params: IOrderPageQuery) => {
  return request<IOrderPageResult>({
    url: '/order/conditionSearch',
    method: 'get',
    params
  });
};

/**
 * 查询订单详情
 * @param id - 订单id
 */
export const getOrderDetailById = (id: number) => {
  return request<IOrderDetail>({
    url: `/order/details/${id}`,
    method: 'get'
  });
};

/**
 * 各个状态的订单数量统计
 */
export const getOrderStatusStatistics = () => {
  return request<IOrderStatistics>({
    url: '/order/statistics',
    method: 'get'
  });
};

/**
 * 接单
 * @param data - { id }
 */
export const confirmOrder = (data: { id: number }) => {
  return request({
    url: '/order/confirm',
    method: 'put',
    data
  });
};

/**
 * 拒单
 * @param data - { id, rejectionReason }
 */
export const rejectOrder = (data: { id: number; rejectionReason: string }) => {
  return request({
    url: '/order/rejection',
    method: 'put',
    data
  });
};

/**
 * 取消订单
 * @param data - { id, cancelReason }
 */
export const cancelOrder = (data: { id: number; cancelReason: string }) => {
  return request({
    url: '/order/cancel',
    method: 'put',
    data
  });
};

/**
 * 派送订单
 * @param id - 订单id
 */
export const deliverOrder = (id: number) => {
  return request({
    url: `/order/delivery/${id}`,
    method: 'put'
  });
};

/**
 * 完成订单
 * @param id - 订单id
 */
export const completeOrder = (id: number) => {
  return request({
    url: `/order/complete/${id}`,
    method: 'put'
  });
};
